<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>语料修改</title>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <!-- 引入 jquery CDN -->
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>

    <style>
        /* 全局样式（与导入页面一致，省略重复代码） */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Poppins', sans-serif;
        }

        body {
            background: linear-gradient(135deg, #e0f7fa, #f4f4f9);
            min-height: 100vh;
        }

        /* 导航栏优化 */
        .navbar {
            height: 80px;
            background: linear-gradient(45deg, #0084ff, #00c3ff);
            display: flex;
            align-items: center;
            padding: 0 60px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            position: fixed;
            width: 100%;
            z-index: 100;
            gap: 30px;
        }

        .navbar a {
            color: #fff;
            font-size: 1rem;
            font-weight: 500;
            text-decoration: none;
            padding: 12px 20px;
            border-radius: 20px;
            transition: background-color 0.3s ease;
        }

        .navbar a:hover {
            background-color: rgba(255, 255, 255, 0.1);
        }

        .navbar a.active {
            background: rgba(255, 255, 255, 0.15);
        }

        .main-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 120px 40px 40px;
        }

        /* 语料修改模块新增样式 */
        .corpus-modify {
            background: #fff;
            padding: 30px 40px;
            border-radius: 16px;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
        }

        .corpus-modify h1 {
            font-size: 2.2rem;
            font-weight: 600;
            color: #1a1a1a;
            margin-bottom: 30px;
        }

        textarea {
            width: 100%;
            height: 300px;
            padding: 18px 24px;
            border: 1px solid #e0e0e0;
            border-radius: 16px;
            font-size: 1rem;
            color: #333;
            resize: vertical;
            margin-bottom: 30px;
        }

        .button-group {
            display: flex;
            gap: 20px;
        }

        button {
            /* 继承导入页面样式，新增取消按钮样式 */
            padding: 14px 32px;
            border-radius: 24px;
            cursor: pointer;
            transition: transform 0.3s ease;
        }

        button.save {
            background: linear-gradient(45deg, #0084ff, #00c3ff);
            color: #fff;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        }

        button.cancel {
            background: #f4f4f9;
            color: #666;
            box-shadow: none;
        }

        button:hover {
            transform: translateY(-2px);
        }

        button.cancel:hover {
            background: #f0f0f0;
        }

        @media (max-width: 768px) {
            .corpus-modify h1 {
                font-size: 1.8rem;
            }

            textarea {
                height: 250px;
            }
        }
    </style>
</head>

<body>
    <div class="navbar">
        <a href="/MainPagehtml/MainPage.html">首页</a>
        <a href="/analysis">情感分析</a>
        <a href="/MainPagehtml/CorpusImport.html">语料导入</a>
        <a href="/MainPagehtml/CorpusModify.html" class="active">语料修改</a> <!-- 激活状态 -->
        <a href="/MainPagehtml/CorpusQuery.html">语料查询</a>
        <a href="/MainPagehtml/userModelCorpus.html">模型语料</a>
        <!--<a href="/MainPagehtml/ModelShow.html">模型效果</a>-->
    </div>

    <div class="main-container">
        <div class="corpus-modify">
            <h1>编辑语料内容</h1>
            <textarea id="corpusText" placeholder="在此处修改语料...">
                示例语料内容：
                [情感]
                [这是一段需要修改的语料...]
            </textarea>
            <div class="button-group">
                <button class="save" onclick="saveCorpus()">保存修改</button>
                <button class="cancel" onclick="resetCorpus()">取消修改</button>
            </div>
        </div>
    </div>

    <script>
        // 模拟语料初始内容（可从后端获取）
        const initialText = `
                示例语料内容：
                [情感]
                [这是一段需要修改的语料...]
        `;
        document.getElementById('corpusText').value = initialText.trim();

        function saveCorpus() {
            const text = document.getElementById('corpusText').value.trim();
            const lines = text.split('\n');
            const firstLine = lines[0];
            const restLines = lines.slice(1).join('\n');
            if (text) {
                //实际开发中此处调用后端接口保存
                $.ajax({
                    method: 'Post',
                    url: '/modify',
                    dataType: 'json',
                    contentType: 'application/json;charset=utf-8',
                    data: JSON.stringify({
                        'emotion': firstLine,
                        'content': restLines
                    }),
                    success: function (data) {
                        var result = data.status;
                        if (result === 'success') {
                            alert(`语料修改成功！\n`);
                        } else {
                            alert("语料修改失败！");
                        }
                    }
                });
            } else {
                alert('语料内容不能为空！');
            }
        }

        function resetCorpus() {
            document.getElementById('corpusText').value = initialText.trim();
        }

        // 导航栏激活状态（同导入页面）
        const currentUrl = window.location.href;
        const navLinks = document.querySelectorAll('.navbar a');
        navLinks.forEach(link => {
            if (currentUrl.includes(link.getAttribute('href'))) {
                link.classList.add('active');
            }
        });
    </script>
</body>

</html>
